package com.pic.mgt.dao;

import java.util.Map;
import java.util.Vector;

import org.springframework.dao.DataAccessException;

import com.pic.mgt.utils.SqlScriptUtils;

public abstract class MessageDao extends BasicDao implements IMessageDao{
	// insert basic 相關設定
	private final String insertBasicSqlScript;
	
	public MessageDao() {
		super();
		
		// 建立 Insert Basic 的 Sql Script
		insertBasicSqlScript = createInsertBasicSQLScript();
	}
	
	public String createInsertBasicSQLScript() {
		Vector<String> insertBasicFieldsVector = new Vector<String>();
		
		// 要新增的欄位
		insertBasicFieldsVector.add(MessageDao._confirmationFile);
		insertBasicFieldsVector.add(MessageDao._transactionFile);
		insertBasicFieldsVector.add(MessageDao._transactionTime);
		insertBasicFieldsVector.add(MessageDao._unitName);
		insertBasicFieldsVector.add(MessageDao._terminalId);

		return SqlScriptUtils.createNamedParamInsertScript(getTableName(),
															insertBasicFieldsVector);
	}

	@Override
	public int insertBasic(Map<String, Object> insertValuesMap)
			throws DataAccessException {
		if (null != insertValuesMap && !insertValuesMap.isEmpty()) {
			return
				super.namedParameterJdbcTemplate.update(this.insertBasicSqlScript,
														insertValuesMap);
		}
		else {
			return 0;
		}
	}
}
